/*
*
* */
Rsd.define('Rsd.Faith.controls.XiaoQuListView', {
    extend: 'Rsd.control.ListView',
    xtype: 'list-xiaoqu',
    requires: ['Rsd.control.AutoComplete','Rsd.Faith.stores.XiaoQuStore'],
    margin: '0 0 0 0',
    width: 120,
    itemSelectedCls:'x-selected',
    itemHover:true,
    itemStyle:{width:'100%',fontWeight:'normal'},
    listType:'decimal',
    label:{
        xtype:'toolBar',
        width:'100%',
        height:'40px',
        layout:'hbox',
        margin:'5 0 5 0',
        style:{lineHeight:'30px',backgroundColor:'#e3e3e3'},
        items:[
            {
                xtype:'autocomplete',
                label:'小区',
                width:230,
                //searchHandler:'search_xiao_qu',
                autoCompleteHandler:'auto_complete',
                valueChanged:'on_changed',
                margin:'0 0 0 10'
            },
            {
                xtype:'link',
                style:{fontWeight:'normal',textAlign:'center'},
                text:'[查找]',
                margin:'0 5 15 0',
                width:50,
                align:'right',
                handler:'btn_find'
            }
        ]
    },
    /*
    * */
    constructor: function ListMenu(config) {

        this.apply(config);

    },
    auto_complete:function(value,callback)
    {
        var _list = [];
        if(Rsd.isEmpty(value))
        {
            callback(_list);
            return;
        }

        var _store = Rsd.create('Rsd.Faith.stores.XiaoQuStore',{});
        _store.load({},function (data) {
            //console.log(data);
            var list = data.data;
            var str = '';
            for(var i in list)
            {
                str = list[i].MingCheng + list[i].BianHao;
                if(str.indexOf(value)<0 )
                {
                    continue;
                }
                else
                {
                    _list.push({id:'b_'+list[i].BianHao,key:list[i].BianHao,text:list[i].MingCheng +'('+list[i].BianHao+')'} );

                }
            }

            callback(_list);
        });

    },
    on_changed:function on_changed(sender,e)
    {
        if(sender.valueItem)
        {
            this.select(sender.valueItem.id);
            this.scrollCurrentIntoView(sender.valueItem.id,true);
        }
    },
    btn_find:function btn_find()
    {
        var ming_cheng = this.label.content.items[0].getText();

        this.loadData(ming_cheng);
    },
    /*
    *
    * */
    loadData:function loadData(mingCheng)
    {

        var _mingCheng = mingCheng||'';
        //debugger;
        var me = this;
        me.parent.showLoading();
        me.removeAll();
        var _store = Rsd.create('Rsd.Faith.stores.XiaoQuStore',{});
        _store.load({},function (data) {

            var list = data.data;
            var str = '';
            for(var i in list)
            {
                str = list[i].MingCheng;
                if(Rsd.isEmpty(_mingCheng)||!(str.indexOf(_mingCheng) < 0))
                {
                    me.addItems({
                        xtype:'label',
                        margin:'0 0 0 30',
                        id:'b_' + list[i].BianHao,key:list[i].BianHao,
                        text:list[i].MingCheng+'('+list[i].BianHao+')' ,
                        //tip:'地址：'+(list[i].DiZhi||'-')  + '  开发商:'+(list[i].KaiFaShangMingCheng||'-')+'('+(list[i].KaiFaShangBianHao||'-')+')'
                    });
                }
              }

            me.parent.closeLoading();
        });

    }

},function(type) {


});
